#include "CCSParameter.h"
#include "IErrorhandlingSys.h"

#include <shlwapi.h>

CCSParameter::CCSParameter(ParamType Type)
{
	m_ptType = Type;
};
CCSParameter::~CCSParameter()
{
};

CCSEvent &CCSParameter::onChange()
{
	return m_evOnChange;
};

ParamType CCSParameter::getType() const
{
	return m_ptType;
};

lvInt CCSParameter::toInt() const
{
	IErrorHandlingSys::OperationExecuted(lvString(_S("CCSParameter::toInt()")), lvString(_FILE_), __LINE__);

	switch(m_ptType)
	{
	case PT_UNKNOWN:
		{
			IErrorHandlingSys::Error(lvString(_S("Parameter type is unknown! Returning 0...")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_FAILED);
			return 0;
		}break;
	case PT_INTEGER:
		{
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return StrToInt(m_strValue.c_str());
		}break;
	case PT_FLOAT:
		{
			IErrorHandlingSys::Warning(lvString(_S("Conversion float parameter to integer may cause some problems..")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return _tcstod(m_strValue.c_str(), 0);
		}break;
	case PT_BOOLEAN:
		{
			IErrorHandlingSys::Error(lvString(_S("Conversion boolean parameter to integer is not recommended...")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return 0;
		}break;
	};
};
lvFloat CCSParameter::toFloat() const
{
	IErrorHandlingSys::OperationExecuted(lvString(_S("CCSParameter::toFloat()")), lvString(_FILE_), __LINE__);

	switch(m_ptType)
	{
	case PT_UNKNOWN:
		{
			IErrorHandlingSys::Error(lvString(_S("Parameter type is unknown! Returning 0...")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_FAILED)
			return 0;
		}break;
	case PT_INTEGER:
		{
			IErrorHandlingSys::Warning(lvString(_S("Conversion integer parameter to float may cause some problems..")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return _tcstod(m_strValue.c_str(), 0);
		}break;
	case PT_FLOAT:
		{
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return _tcstod(m_strValue.c_str(), 0);
		}break;
	case PT_BOOLEAN:
		{
			IErrorHandlingSys::Error(lvString(_S("Conversion boolean parameter to float is not recommended...")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return 0;
		}break;
	};
};
lvBool CCSParameter::toBool() const
{
	IErrorHandlingSys::OperationExecuted(lvString(_S("CCSParameter::toBool()")), lvString(_FILE_), __LINE__);

	switch(m_ptType)
	{
	case PT_UNKNOWN:
		{
			IErrorHandlingSys::Error(lvString(_S("Parameter type is unknown! Returning false...")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_FAILED)
			return false;
		}break;
	case PT_INTEGER:
		{
			IErrorHandlingSys::Warning(lvString(_S("Conversion integer parameter to boolean is not recommended...")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return StrToInt(m_strValue.c_str()) ? true : false;
		}break;
	case PT_FLOAT:
		{
			IErrorHandlingSys::Warning(lvString(_S("Conversion float parameter to boolean is not recommended...")), SUBSYSTEM_ID_DEFAULT);
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return _tcstod(m_strValue.c_str(), 0) ? true : false;
		}break;
	case PT_BOOLEAN:
		{
			IErrorHandlingSys::OperationExit(STATUS_SUCCESFUL);
			return StrToInt(m_strValue.c_str()) ? true : false;
		}break;
	};
};